package com.neuedu.projectedu.controller;

import com.neuedu.projectedu.common.Result;
import com.neuedu.projectedu.utils.COSStorage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

@RestController
@Slf4j
@RequestMapping("/upload")
public class UploadController {

    @PostMapping("/upload")
    public Result upload(MultipartFile file) throws IOException {
        InputStream in = file.getInputStream();
        String type = file.getContentType();
        String filename = file.getOriginalFilename();
        log.info(type);
        log.info(filename);
        String ext=filename.substring(filename.lastIndexOf("."),filename.length());
        String str = COSStorage.upload(in, ext,type);
        return Result.success(str);
    }
}
